<?php

/**
 * @author Eureka
 */
class View
{

	protected static $_instance;
	private $_data = array();
	
	public function __construct()
	{
		
	}
	
	public function __set($name, $value)
	{
		$this->_data[$name] = $value;
	}

	public function &__get($name)
	{
		return $this->_data[$name];
		if (array_key_exists($key, $this->_data))
		{
			return $this->_data[$name];
		}
	}
	
	public static function getInstance()
	{
		if (is_null(self::$_instance))
		{
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	public function render($view, $params = array())
	{
		ob_start();
		extract($params, EXTR_PREFIX_SAME, 'data');
		$filename =  APPLICATION_PATH . "/views/$view.php";
		if(file_exists($filename))
		{
			include_once $filename;
		}
		else
		{
			throw new Exception("View not found");
		}
		$ret = ob_get_contents();
		ob_end_clean();
		print $ret;
	}

}

?>
